home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / gas / gassrc04.zoo / ns32k.c < prev    next >
C/C++ Source or Header  |  1991-01-24  |  51KB  |  1,769 lines

  1. /* ns32k.c  -- Assemble on the National Semiconductor 32k series
  2.    Copyright (C) 1987 Free Software Foundation, Inc.
  3.  
  4. This file is part of GAS, the GNU Assembler.
  5.  
  6. GAS is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GAS is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GAS; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #define NS32K
  21. /*#define SHOW_NUM 1*/ /* uncomment for debugging */
  22.  
  23. #include <stdio.h>
  24. #include <ctype.h>
  25. #ifdef USG
  26. #include <string.h>
  27. #else
  28. #include <strings.h>
  29. #endif
  30. #include "ns32k-opcode.h"
  31. #include "as.h"
  32. #include "obstack.h"
  33. #include "frags.h"
  34. #include "struc-symbol.h"
  35. #include "flonum.h"
  36. #include "expr.h"
  37. #include "md.h"
  38. #include "hash.h"
  39. #include "write.h"
  40. #include "symbols.h"
  41.  
  42. /* Macros */
  43. #define IIF_ENTRIES 13                /* number of entries in iif */ 
  44. #define PRIVATE_SIZE 256            /* size of my garbage memory */
  45. #define MAX_ARGS 4
  46. #define DEFAULT    -1        /* addr_mode returns this value when plain constant or label is encountered */
  47.  
  48. #define IIF(ptr,a1,c1,e1,g1,i1,k1,m1,o1,q1,s1,u1) \
  49.   iif.iifP[ptr].type= a1; \
  50.   iif.iifP[ptr].size= c1; \
  51.   iif.iifP[ptr].object= e1; \
  52.   iif.iifP[ptr].object_adjust= g1; \
  53.   iif.iifP[ptr].pcrel= i1; \
  54.   iif.iifP[ptr].pcrel_adjust= k1; \
  55.   iif.iifP[ptr].im_disp= m1; \
  56.   iif.iifP[ptr].relax_substate= o1; \
  57.   iif.iifP[ptr].bit_fixP= q1; \
  58.   iif.iifP[ptr].addr_mode= s1; \
  59.   iif.iifP[ptr].bsr= u1;
  60.  
  61. #ifdef SEQUENT_COMPATABILITY
  62. #define LINE_COMMENT_CHARS "|"
  63. #define ABSOLUTE_PREFIX '@'
  64. #define IMMEDIATE_PREFIX '#'
  65. #endif
  66.  
  67. #ifndef LINE_COMMENT_CHARS
  68. #define LINE_COMMENT_CHARS "#"
  69. #endif
  70.  
  71. char comment_chars[] = "#";
  72. char line_comment_chars[] = LINE_COMMENT_CHARS;
  73. #if !defined(ABSOLUTE_PREFIX) && !defined(IMMEDIATE_PREFIX)
  74. #define ABSOLUTE_PREFIX '@'    /* One or the other MUST be defined */
  75. #endif
  76.  
  77. struct addr_mode {
  78.   char mode;            /* addressing mode of operand (0-31) */
  79.   char scaled_mode;        /* mode combined with scaled mode */
  80.   char scaled_reg;        /* register used in scaled+1 (1-8) */
  81.   char float_flag;        /* set if R0..R7 was F0..F7 ie a floating-point-register */
  82.   char am_size;            /* estimated max size of general addr-mode parts*/
  83.   char im_disp;            /* if im_disp==1 we have a displacement */
  84.   char pcrel;            /* 1 if pcrel, this is really redundant info */
  85.   char disp_suffix[2];        /* length of displacement(s), 0=undefined */
  86.   char *disp[2];        /* pointer(s) at displacement(s)
  87.                               or immediates(s)     (ascii) */
  88.   char index_byte;        /* index byte */
  89. };
  90. typedef struct addr_mode addr_modeS;
  91.  
  92.  
  93. char *freeptr,*freeptr_static; /* points at some number of free bytes */
  94. struct hash_control *inst_hash_handle;
  95.  
  96. struct ns32k_opcode *desc; /* pointer at description of instruction */
  97. addr_modeS addr_modeP;
  98. char EXP_CHARS[] = "eE";
  99. char FLT_CHARS[] = "fd"; /* we don't want to support lowercase, do we */
  100. long omagic = OMAGIC;
  101. void md_number_to_disp();
  102. void md_number_to_imm();
  103. segT evaluate_expr();
  104. void fix_new_ns32k();
  105.  
  106. /* UPPERCASE denotes live names 
  107.  * when an instruction is built, IIF is used as an intermidiate form to store
  108.  * the actual parts of the instruction. A ns32k machine instruction can
  109.  * be divided into a couple of sub PARTs. When an instruction is assembled
  110.  * the appropriate PART get an assignment. When an IIF has been completed it's
  111.  * converted to a FRAGment as specified in AS.H */
  112.  
  113. /* internal structs */
  114. struct option {
  115.   char *pattern;
  116.   unsigned long or;
  117.   unsigned long and;
  118. };
  119.  
  120. typedef struct {
  121.   int            type;        /* how to interpret object */
  122.   int            size;        /* Estimated max size of object */
  123.   unsigned long        object;        /* binary data */
  124.   int            object_adjust;    /* number added to object */
  125.   int            pcrel;        /* True if object is pcrel */
  126.   int            pcrel_adjust;    /* It's value reflects the length in bytes from the instruction start to the displacement */
  127.   int            im_disp;    /* True if the object is a displacement */
  128.   relax_substateT    relax_substate; /* Initial relaxsubstate */
  129.   bit_fixS        *bit_fixP;    /* Pointer at bit_fix struct */ 
  130.   int            addr_mode;    /* What addrmode do we associate with this iif-entry */
  131.   char            bsr;        /* Sequent hack */
  132. }iif_entryT;                /* Internal Instruction Format */
  133. struct int_ins_form {
  134.   int        instr_size;        /* Max size of instruction in bytes. */
  135.   iif_entryT    iifP[IIF_ENTRIES+1];
  136. };
  137. struct int_ins_form iif;
  138. expressionS exprP;
  139. char *input_line_pointer;
  140. /* description of the PARTs in IIF 
  141.  *object[n]:
  142.  * 0    total length in bytes of entries in iif
  143.  * 1    opcode
  144.  * 2    index_byte_a
  145.  * 3    index_byte_b
  146.  * 4    disp_a_1
  147.  * 5    disp_a_2
  148.  * 6    disp_b_1
  149.  * 7    disp_b_2
  150.  * 8    imm_a
  151.  * 9    imm_b
  152.  * 10    implied1
  153.  * 11    implied2
  154.  * 
  155.  * For every entry there is a datalength in bytes. This is stored in size[n].
  156.  *     0,    the objectlength is not explicitly given by the instruction
  157.  *        and the operand is undefined. This is a case for relaxation.
  158.  *        Reserve 4 bytes for the final object.
  159.  *
  160.  *     1,    the entry contains one byte
  161.  *     2,    the entry contains two bytes
  162.  *     3,    the entry contains three bytes
  163.  *     4,    the entry contains four bytes
  164.  *    etc
  165.  *
  166.  * Furthermore, every entry has a data type identifier in type[n].
  167.  *
  168.  *      0,    the entry is void, ignore it.
  169.  *      1,    the entry is a binary number.
  170.  *     2,    the entry is a pointer at an expression.
  171.  *        Where expression may be as simple as a single '1',
  172.  *        and as complicated as  foo-bar+12,
  173.  *         foo and bar may be undefined but suffixed by :{b|w|d} to
  174.  *        control the length of the object.
  175.  *
  176.  *     3,    the entry is a pointer at a bignum struct
  177.  *
  178.  *
  179.  * The low-order-byte coresponds to low physical memory.
  180.  * Obviously a FRAGment must be created for each valid disp in PART whose
  181.  * datalength is undefined (to bad) .
  182.  * The case where just the expression is undefined is less severe and is
  183.  * handled by fix. Here the number of bytes in the objectfile is known.
  184.  * With this representation we simplify the assembly and separates the
  185.  * machine dependent/independent parts in a more clean way (said OE)
  186.  */
  187.  
  188. struct option opt1[]= /* restore, exit */
  189. {
  190.   { "r0",    0x80,    0xff    },
  191.   { "r1",    0x40,    0xff    },
  192.   { "r2",    0x20,    0xff    },
  193.   { "r3",    0x10,    0xff    },
  194.   { "r4",    0x08,    0xff    },
  195.   { "r5",    0x04,    0xff    },
  196.   { "r6",    0x02,    0xff    },
  197.   { "r7",    0x01,    0xff    },
  198.   {  0 ,    0x00,    0xff    }
  199. };
  200. struct option opt2[]= /* save, enter */
  201. {
  202.   { "r0",    0x01,    0xff    },
  203.   { "r1",    0x02,    0xff    },
  204.   { "r2",    0x04,    0xff    },
  205.   { "r3",    0x08,    0xff    },
  206.   { "r4",    0x10,    0xff    },
  207.   { "r5",    0x20,    0xff    },
  208.   { "r6",    0x40,    0xff    },
  209.   { "r7",    0x80,    0xff    },
  210.   {  0 ,    0x00,    0xff    }
  211. };
  212. struct option opt3[]= /* setcfg */
  213. {
  214.   { "c",    0x8,    0xff    },
  215.   { "m",    0x4,    0xff    },
  216.   { "f",    0x2,    0xff    },
  217.   { "i",    0x1,    0xff    },
  218.   {  0 ,    0x0,    0xff    }
  219. };
  220. struct option opt4[]= /* cinv */
  221. {
  222.   { "a",    0x4,    0xff    },
  223.   { "i",    0x2,    0xff    },
  224.   { "d",    0x1,    0xff    },
  225.   {  0 ,    0x0,    0xff    }
  226. };
  227. struct option opt5[]= /* string inst */
  228. {
  229.   { "b",    0x2,    0xff    },
  230.   { "u",    0xc,    0xff    },
  231.   { "w",    0x4,    0xff    },
  232.   {  0 ,    0x0,    0xff    }
  233. };
  234. struct option opt6[]= /* plain reg ext,cvtp etc */
  235. {
  236.   { "r0",    0x00,    0xff    },
  237.   { "r1",    0x01,    0xff    },
  238.   { "r2",    0x02,    0xff    },
  239.   { "r3",    0x03,    0xff    },
  240.   { "r4",    0x04,    0xff    },
  241.   { "r5",    0x05,    0xff    },
  242.   { "r6",    0x06,    0xff    },
  243.   { "r7",    0x07,    0xff    },
  244.   {  0 ,    0x00,    0xff    }
  245. };
  246.  
  247. #if !defined(NS32032) && !defined(NS32532)
  248. #define NS32032
  249. #endif
  250.  
  251. struct option cpureg_532[]= /* lpr spr */
  252. {
  253.   { "us",    0x0,    0xff    },
  254.   { "dcr",    0x1,    0xff    },
  255.   { "bpc",    0x2,    0xff    },
  256.   { "dsr",    0x3,    0xff    },
  257.   { "car",    0x4,    0xff    },
  258.   { "fp",    0x8,    0xff    },
  259.   { "sp",    0x9,    0xff    },
  260.   { "sb",    0xa,    0xff    },
  261.   { "usp",    0xb,    0xff    },
  262.   { "cfg",    0xc,    0xff    },
  263.   { "psr",    0xd,    0xff    },
  264.   { "intbase",    0xe,    0xff    },
  265.   { "mod",    0xf,    0xff    },
  266.   {  0 ,    0x00,    0xff    }
  267. };
  268. struct option mmureg_532[]= /* lmr smr */
  269. {
  270.   { "mcr",    0x9,    0xff    },
  271.   { "msr",    0xa,    0xff    },
  272.   { "tear",    0xb,    0xff    },
  273.   { "ptb0",    0xc,    0xff    },
  274.   { "ptb1",    0xd,    0xff    },
  275.   { "ivar0",    0xe,    0xff    },
  276.   { "ivar1"